import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;

public class myScanner extends JPanel
{
	private JFileChooser chooser;
	private JButton getName;
	private File file = null;
	
	private String get = "Get";
	
	public myScanner()
	{
		chooser = new JFileChooser();
		getName = new JButton("Click to choose the text file");
		add(getName);
		setPreferredSize(new Dimension(500, 100));
		getName.addActionListener(new ButtonListener(get));
	}
	
	public File getFile()
	{
		return file;
	}
	
	private class ButtonListener implements ActionListener 
	{
		String buttonName;
		String get = "Get";
		
		public ButtonListener(String Name)
		{
			this.buttonName = Name;	
		}
		
		@Override
		public void actionPerformed(ActionEvent arg0) 
		{
			if (buttonName.equals(get))
			{
				int status = chooser.showOpenDialog(null);
				if (status != JFileChooser.APPROVE_OPTION)
				{
					//do nothing
				}
				else
				{
					//get file
					file = chooser.getSelectedFile();
					myDriver.counter =1 ;
					myDriver.frame.dispose();
				}
			}
		}
	}
}